import QtQuick 2.0
import QtMultimedia 5.12

Item {
    anchors.fill: parent
    anchors.margins: 30

    VideoOutput {
        id: video
        anchors.fill: parent
        anchors.bottomMargin: 100
        source: camera
    }

    Camera {
        id: camera
    }

    Rectangle {
        id: btn
        width: 100
        height: 20
        anchors.right: video.right
        anchors.rightMargin: 10
        anchors.bottom: video.bottom
        anchors.bottomMargin: 10
        color: "white"
        border.color: "black"
        Text {
            text: "Take Photo"
            anchors.centerIn: parent
        }
        MouseArea {
            anchors.fill: parent
            onClicked: {
                camera.imageCapture.capture();
            }
        }
    }

    Connections {
        target: camera.imageCapture
        onImageSaved: {
            photos.append({"imgPath": "file:///" + path});
            picsView.positionViewAtEnd();
        }
    }

    ListModel {
        id: photos
    }

    ListView {
        id: picsView
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.top: video.bottom
        anchors.topMargin: 15
        height: 60
        spacing: 10
        orientation: ListView.Horizontal
        model: photos
        delegate: Image {
            height: parent.height
            source: imgPath
            fillMode: Image.PreserveAspectFit
        }
        Rectangle {
            anchors.fill: parent
            color: "black"
            opacity: 0.2
        }
    }
}
